package org.zn.mvcbase.response;

/**
 * @ProjectName:91isoft_oa
 * @Description:
 * @Copyright: Copyright (c) 2016

 * @author: 周楠
 * @date 2016年3月21日 上午11:06:22
 */

public class CommonDataConventer implements DataConverter {

	@Override
	public ResponseMessage converter(Metadata md, ResponseMessage rm) {

		if (rm.getMapperKey().equals("datamessage")) {

			DataMessage dm = (DataMessage) rm;

			dm.setDatamap(md.getDataMap());
			dm.setStatus(md.getState());

		} else if (rm.getMapperKey().equals("pagedata")) {

			PaginationData pd = (PaginationData) rm;

			pd.setPage(md.getPage());
			pd.setStatus(md.getState());

		} else if (rm.getMapperKey().equals("mainstatus")) {

			MainStatus ms = (MainStatus) rm;

			ms.setStatus(md.getState());

		} else if (rm.getMapperKey().equals("validmessage")) {

			ValidatedMessage vm = (ValidatedMessage) rm;

			vm.setStatus(md.getState());
			vm.setValidmessage(md.getValidresult().getErrorsMap());

		}else if (rm.getMapperKey().equals("detail")) {

			DetailedMessage dm = (DetailedMessage) rm;

			dm.setStatus(md.getState());
			dm.setDetail(md.getDetailObject());

		}
		

		return rm;
	}
}
